<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <input name="operationUserId" style="display: none;" id="treeId"/>
                <div class="select-list">
                    <ul>
                        <li>
                            直购电用户：
                            <select name="userId">
                                <option th:text="全部" value=""></option>
                                <option th:each="user : ${users}" th:text="${user.name}" th:value="${user.id}"></option>
                            </select>
                        </li>

                        <li>
                            供电企业：<input type="text" name="deptName" onclick="selectDeptTree()" readonly="true"
                                        id="treeName">
                        </li>

                        <li>
                            电压等级：<select id="voltageGrade" name="voltageGrade"
                                         th:with="type=${@dict.getType('voltage_grade')}">
                            <option th:text="全部" value=""></option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>

                        <li>
                            录入次数：<input type="number" name="name"/>
                        </li>

                        <li class="select-time">
                            <label>电费月份： </label>
                            <input type="text"  id="resultDate" placeholder="统计日期" name="resultDate"/>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="service:basics:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()"
               shiro:hasPermission="service:basics:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="service:basics:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="exportSelect()" shiro:hasPermission="service:basics:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-warning" onclick="luru()">
                <i class="fa fa-pencil"></i> 录入
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var listFlag = [[${@permission.hasPermi('service:basics:edit')}]];
    var editFlag = [[${@permission.hasPermi('service:basics:edit')}]];
    var removeFlag = [[${@permission.hasPermi('service:basics:remove')}]];
    var voltageGradeDatas = [[${@dict.getType('voltage_grade')}]];
    var priceDetailTypeDatas = [[${@dict.getType('price_detail_type')}]];
    var prefix = ctx + "service/basics";

    layui.use('laydate', function() {
        var laydate = layui.laydate;
        laydate.render({
            elem: "#resultDate",
            type: 'month',
            theme: 'molv',
            trigger: 'click',
            done: function(value, date) {}
        });
    });

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "电量电费录入数据基础",
            search: false,
            showExport: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'user.name',
                    title: '直购电用户',
                    sortable: true
                },
                {
                    field: 'operationUserId',
                    title: '操作人',
                    sortable: true,
                    visible: false
                },
                {
                    field: 'name',
                    title: '录入次数',
                    sortable: true
                },
                {
                    field: 'resultDate',
                    title: '电费月份',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return value!=null?new Date(value).Format('yyyy-MM'):"";
                    }
                },
                {
                    field: 'voltageGrade',
                    title: '电压等级',
                    sortable: true,
                    visible:false,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(voltageGradeDatas, value);
                    }
                },
                {
                    field: 'eleAccount',
                    title: '电量'
                },
                {
                    field: 'dHPrice',
                    title: '到户电价'
                },
                {
                    field: 'dHAccount',
                    title: '到户电费'
                },
                {
                    field: 'priceDetailType',
                    title: '目录电价明细类别',
                    sortable: true,
                    visible:false,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(priceDetailTypeDatas, value);
                    }
                },
                {
                    field: 'operationDate',
                    title: '操作日期',
                    sortable: true,
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-info btn-xs ' + listFlag + '" href="#" onclick="detail(\'' + row.id + '\')"><i class="fa fa-list-ul"></i>费用列表</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    Date.prototype.Format = function (fmt) {
        var o = {
            "M+": this.getMonth() + 1, //月份
            "d+": this.getDate(), //日
            "h+": this.getHours(), //小时
            "m+": this.getMinutes(), //分
            "s+": this.getSeconds(), //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }

    /*费用列表-详细*/
    function detail(dictId) {
        var url = prefix + '/detail/' + dictId;
        createMenuItem(url, "费用列表");
    };
    function exportSelect() {
        var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.confirm("确认要导出选中的" + rows.length + "条数据吗?", function () {
            var url = prefix + '/exportSelect';
            var data = {"ids": rows.join()};
            var config = {
                url: url,
                type: "post",
                dataType: "json",
                data: data,
                success: function (result) {
                    if (result.code == web_status.SUCCESS) {
                        window.location.href = ctx + "common/download?fileName=" + result.msg + "&delete=" + true;
                    } else {
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                }
            };
            $.ajax(config);
        });
    };
    /**数据录入按钮**/
    function luru() {
        var url = prefix + "/luru";
        createMenuItem(url, "费用列表");
    }
    /*用户管理-新增-选择部门树*/
    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择所属供电企业',
            width: "380",
            url: ctx + "system/dept/selectDeptTree/" + deptId,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }
    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }
    //    function reset(formId) {
    //        var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
    //        $("#" + currentId)[0].reset();
    //        $("#treeId").val("")
    //    }
</script>
</body>
</html>